//
//  HERoomApplyCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2021/3/2.
//  Copyright © 2021 honglutec. All rights reserved.
//

#import "HERoomApplyCell.h"

@interface HERoomApplyCell ()

@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *numLb;
@property (nonatomic, strong) UIButton *helpBtn;

@end

@implementation HERoomApplyCell
 

- (instancetype)initWithFrame:(CGRect)frame {
    if (self=[super initWithFrame:frame]) {
        
        // Fix the bug in iOS7 - initial constraints warning
        self.contentView.bounds = [UIScreen mainScreen].bounds;
        
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *warp = [UIView new];
    warp.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    warp.layer.shadowOffset = CGSizeMake(0,5);
    warp.layer.shadowOpacity = 1;
    warp.layer.shadowRadius = 8;
    warp.layer.cornerRadius = 8;
    [self.contentView addSubview:warp];

    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView).mas_offset(10);
        make.right.equalTo(self.contentView).mas_offset(-10);
        make.height.mas_greaterThanOrEqualTo(80);
        make.bottom.equalTo(self.contentView).mas_offset(-20);
    }];
    
     
    _titleLb = [UILabel new];
    _titleLb.textColor = CNavBgColor;
    _titleLb.font = DYBlodFont(16);
    _titleLb.numberOfLines = 0;
    _titleLb.textAlignment = NSTextAlignmentCenter;
    [warp addSubview:_titleLb];
 
    _numLb = [UILabel new];
    _numLb.textColor = CNavLightBlackColor;
    _numLb.font = DYFont(15);
    _numLb.numberOfLines = 0;
    _numLb.textAlignment = NSTextAlignmentCenter;
    [warp addSubview: _numLb];
    
    _helpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _helpBtn.backgroundColor = CNavBgColor;
    [_helpBtn setTitle:@"我要助力" forState:UIControlStateNormal];
    [_helpBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    _helpBtn.layer.cornerRadius = 8;
    _helpBtn.titleLabel.font = DYFont(16);
    [warp addSubview: _helpBtn];
    
    [_helpBtn addTarget:self action:@selector(helpBtnClick) forControlEvents:UIControlEventTouchUpInside];

    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).mas_offset(15);
        make.left.equalTo(warp).mas_offset(15);
        make.right.equalTo(warp).mas_offset(-15);
    }];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
 
    [_numLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
        make.left.equalTo(warp).mas_offset(15);
        make.right.equalTo(warp).mas_offset(-15);
    }];
    
    [_helpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_numLb.mas_bottom).mas_offset(10);
        make.centerX.equalTo(warp);
        make.width.offset([_helpBtn.titleLabel.text widthForFont: _helpBtn.titleLabel.font] + 20);
        make.bottom.equalTo(warp).mas_offset(-15);
    }];
}
 
- (void)setModel:(HERoomApplyModel *)model {
    _model = model;
    _titleLb.text = model.applyTitle;
    _numLb.text = model.KnumText;
}

- (void)helpBtnClick {
    if ([_delegate respondsToSelector:@selector(helpApplyRoomWithCell:)]) {
        [_delegate helpApplyRoomWithCell: _model];
    }
}

@end

